/**
 * 
 */
package com.alstudio.service;

import java.io.File;
import java.util.ArrayList;

import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.IBinder;
import android.text.TextUtils;

import com.alstudio.app.ALLocalEnv;
import com.alstudio.app.VersionConfig;
import com.alstudio.core.app.ALSplashManager;
import com.alstudio.core.message.note.NoteMessageManager;
import com.alstudio.core.message.system.SystemMessageManager;
import com.alstudio.core.telephone.ALTelephoneCallStateManager;
import com.alstudio.core.voip.ALVoipCallManager;
import com.alstudio.core.voip.CallState;
import com.alstudio.event.ALEventDeliver;
import com.alstudio.intent.ALIntentEvent;
import com.alstudio.module.ALModuleManager;
import com.alstudio.module.push.ALPushManager;
import com.alstudio.module.voip.ALVoipModuleManager;
import com.alstudio.module.xmpp.ALXmppEventCallback;
import com.alstudio.module.xmpp.ALXmppModuleManager;
import com.alstudio.module.xmpp.EventHandler.xmpp.ALXmppEventHandler;
import com.alstudio.module.xmpp.distributor.distributor.CheckDistributorEventCallback;
import com.alstudio.module.xmpp.distributor.distributor.DistributorEvent;
import com.alstudio.module.xmpp.protocol.xmpp.ALXmppAdapter;
import com.alstudio.module.xmpp.protocol.xmpp.data.ALXmppEventType;
import com.alstudio.module.xmpp.protocol.xmpp.packact.ALMessage;
import com.alstudio.module.xmpp.request.ALUiXmppRequestCreator;
import com.alstudio.module.xmpp.request.ALUiXmppRequestType;
import com.alstudio.pojo.ALXmppEvent;
import com.alstudio.pojo.module.local.LocalConfigure;
import com.alstudio.pojo.module.server.ServerInfo;
import com.alstudio.pojo.module.user.User;
import com.alstudio.ui.module.account.GetAccountActivity;
import com.alstudio.ui.module.voip.CallActivity;
import com.alstudio.utils.account.ALAccount;
import com.alstudio.utils.account.UserProfileManager;
import com.alstudio.utils.android.net.ALConnectionManager;
import com.alstudio.utils.android.net.ALNetworkReceiver;
import com.alstudio.utils.asyncTask.ALAsycTask;
import com.alstudio.utils.asyncTask.ALAsyncTaskCallback;
import com.alstudio.utils.image.BitmapUtil;
import com.alstudio.utils.log.ALLog;
import com.alstudio.utils.notification.SystemNotificationEnvConfig;
import com.alstudio.utils.notification.SystemSettings;
import com.alstudio.view.toast.MyToastUtil;
import com.loovee.imaohu.R;

/**
 * @author alonso lee
 * 
 */
public class BackgroundService extends Service implements ALXmppEventCallback,
		CheckDistributorEventCallback {

	private ALXmppEventHandler mXmppEventHandler;
	private ALNetworkReceiver mConnectionReceiver = new ALNetworkReceiver();
	// 用于判断获取vcard后是否要发送出席消息
	private boolean sendPresenceRequest = false;
	private ALXmppAdapter adapter;

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Service#onCreate()
	 */
	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		return super.onStartCommand(intent, flags, startId);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Service#onStart(android.content.Intent, int)
	 */
	@Override
	@Deprecated
	public void onStart(Intent intent, int startId) {
		// TODO Auto-generated method stub
		super.onStart(intent, startId);
		initService();
		ALLog.d("开启后台服务");
	}

	/**
	 * 初始化后台服务
	 */
	private void initService() {
		mXmppEventHandler = new ALXmppEventHandler();
		ALLocalEnv.adapter = new ALXmppAdapter(mXmppEventHandler);

		initApp();
		initModules();

		IntentFilter filter = new IntentFilter();
		filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
		registerReceiver(mConnectionReceiver, filter);
		initPjsip();
		ALEventDeliver.getDefaultAlEventDeliver().register(this);
		ALTelephoneCallStateManager.getDefaultManager();
		initCompleted();
	}

	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		unregisterReceiver(mConnectionReceiver);
		ALEventDeliver.getDefaultAlEventDeliver().unregister(this);
		releasePjsip();
	}

	/**
	 * 初始化 pjsip
	 */
	private void initPjsip() {
		// ALVoipModuleManager.getDefaultALVoipModuleManager().registerModule(null);
	}

	/**
	 * 銷毀pjsip
	 */
	private void releasePjsip() {
		// ALVoipModuleManager.getDefaultALVoipModuleManager().unregisterModule(null);
	}

	private void initModules() {
		// 初始化voip模块
		ALVoipModuleManager voipModule = new ALVoipModuleManager();
		// 初始化xmpp模块
		ALXmppModuleManager xmppModule = new ALXmppModuleManager(ALLocalEnv
				.getLocalEnv().getMyAccount(), ALLocalEnv.adapter);

		ALModuleManager.getDefaultModuleManager().registerModule(voipModule);
		ALModuleManager.getDefaultModuleManager().registerModule(xmppModule);
		// 百度云推送
		ALPushManager.getDefaultPushManager().registerModule(
				getApplicationContext());
	}

	/**
	 * 初始化应用，打开数据库，读取配置文件，读取账号
	 */
	private void initApp() {
		String tmpName = ALLocalEnv.getLocalEnv().getDatabase()
				.loadPrivateAccount();
		if (!TextUtils.isEmpty(tmpName)) {
			ALLog.d("打开数据库" + tmpName);
			ALLocalEnv.getLocalEnv().getDatabase().loadDataBase(tmpName);
		} else {
			// 打开缺省滴数据库
			ALLocalEnv.getLocalEnv().getDatabase().loadDefaultDb();
			ALLog.d("打开缺省数据库");
		}

		// 是否已注销
		boolean isUserLogoff = ALLocalEnv.getLocalEnv().getDatabase()
				.loadSystemSetting();
		ALLog.d("读出来的注销标志是" + isUserLogoff);

		// 读取本地配置文件
		loadLocalConfigure();

		// 读取账号
		ALAccount account = ALLocalEnv.getLocalEnv().getDatabase()
				.loadMyAccount();
		if (TextUtils.isEmpty(account.getUserName())) {
			isUserLogoff = true;
			ALLocalEnv.getLocalEnv().getDatabase()
					.saveSystemSetting(isUserLogoff);
		}
		account.setLogoff(isUserLogoff);
		ALLocalEnv.getLocalEnv().setAccount(account);

		// 初始化本地voip通話管理器
		ALVoipCallManager.getDefaultALVoipManager();
	}

	/**
	 * 从数据库中读取本地配置文件
	 */
	private void loadLocalConfigure() {
		// 从数据库中读取配置文件
		LocalConfigure mConfigure = ALLocalEnv.getLocalEnv().getDatabase()
				.getLocalConfigure();

		if (mConfigure.getServerInfo().getIMServerIP().length() == 0) {
			// 还没有存储到配置文件,初始化一个缺省的值
			ALLog.d("数据库中没有服务器地址,使用本地配置文件");
		} else {
			ALLog.d("###从数据库中读取的im地址为:"
					+ mConfigure.getServerInfo().getIMServerIP() + " http端口为:"
					+ mConfigure.getServerInfo().getHttpPort());
			ServerInfo temp = ALLocalEnv.getLocalEnv().getVersionConfig()
					.getServerInfo();
			temp.setIMServerIP(mConfigure.getServerInfo().getIMServerIP());
			temp.setIMSocketPort(mConfigure.getServerInfo().getIMSocketPort());

			temp.setMediaServerIp(mConfigure.getServerInfo().getMediaServerIp());
			temp.setMediaServerPort(mConfigure.getServerInfo()
					.getMediaServerPort());

			temp.setServerName(mConfigure.getServerInfo().getServerName());
		}
	}

	/**
	 * 初始化成功，通知跳转
	 */
	private void initCompleted() {

		Intent i = new Intent(ALIntentEvent.APP_INIT_COMPLETE);
		sendBroadcast(i);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.ALXmppEventCallback#onALEvent(com.alstudio.pojo
	 * .ALXmppEvent)
	 */
	@Override
	public void onALEvent(ALXmppEvent data) {
		// TODO Auto-generated method stub

		switch (data.getType()) {
		case XMPP_CONNECTION_STATE_CHANGED_EVENT:
			// xmpp连接状态改变
			break;
		case XMPP_CONNECTION_ESTABLISHED_EVENT:
			// 登陆成功
			loginedUpdataDataBase(data);
			break;
		case XMPP_GET_USER_PROFILE_RESULT:
			// 获取个人资料
			handleGetUserProfileEvent(data);
			break;
		case XMPP_CONFILICT_LOGIN_EVENT:
			// 处理被踢下线
			invokeConflictEvent(data);
			break;
		case XMPP_GET_MODIFY_USER_PROFILE_RESULT:
			// 修改个人资料结果，做保存个人资料处理
			handleModifyUserProfileEvent(data);
			break;
		case XMPP_MESSAGE_PACKAGE_RECEIVE_EVENT:
			// 收到新Message消息
			invokeNewMessageReceiveEvent(data);
			break;
		case XMPP_MAKE_CALL_RESULT:
			invokeMakeCallEvent(data);
			break;
		case XMPP_GET_USER_OPTION_RESULT:
			// 得到用户配置文件
			invokeGetUserOptEvent(data);
			break;
		case XMPP_CHECK_BLACK_LIST_RESULT:
			// 得到黑名单
			invokeSaveBlackListAction(data);
			break;
		case XMPP_ACCEPT_INCOMMING_CALL_RESULT:
			if (data.getResponseCode() == ALXmppEvent.RESPONSE_OK) {
				ALVoipCallManager.getDefaultALVoipManager().onCallStateChanged(
						CallState.CALL_ESTABLISED, null);
			}
			break;
		case XMPP_BIND_EMAIL_SUCCESS_RESULT:
			// 邮箱绑定成功通知
			break;
		default:
			break;
		}
	}

	/**
	 * 处理收到新消息事件
	 * 
	 * @param data
	 */
	private void invokeNewMessageReceiveEvent(ALXmppEvent data) {
		switch (data.getMessage().getType()) {
		case ALMessage.NEW_INCOMMING_CALL:
			invokenNewIncommingCallEvent(data.getMessage());
			break;
		case ALMessage.USER_ACCEPT_CALL:
			ALVoipCallManager.getDefaultALVoipManager().onCallStateChanged(
					CallState.CALL_ESTABLISED, null);
			break;
		case ALMessage.USER_HANDUP_CALL:
			ALVoipCallManager.getDefaultALVoipManager().onCallStateChanged(
					CallState.CALL_HANDUP, null);
			break;
		case ALMessage.USER_REJECT_CALL:
			ALVoipCallManager.getDefaultALVoipManager().onCallStateChanged(
					CallState.CALL_REJECT, null);
			break;
		case ALMessage.USER_VOIP_ADDR_SET:
			break;
		case ALMessage.SYSTEM:
			// 收到系统消息啵
			invokeNewSystemMessageReceive(data.getMessage());
			break;
		case ALMessage.CALL_IMAGE_MSG:
			// 通话中的图片消息
			invokeNewCallImageMsgReceive(data.getMessage());
			break;
		case ALMessage.AUDIO_LEAVE:
			// 保存语音留言
			invokeNewNoteMessageReceive(data.getMessage());
			break;
		default:
			break;
		}
	}

	/**
	 * 处理收到新的系统消息
	 * 
	 * @param msg
	 */
	private synchronized void invokeNewSystemMessageReceive(ALMessage msg) {
		// 保存消息
		startSaveSystemMessage(msg);
	}

	/**
	 * 处理收到的通话中图片消息
	 * 
	 * @param msg
	 */
	private synchronized void invokeNewCallImageMsgReceive(ALMessage msg) {
		startSaveCallImageMessage(msg);
	}

	/**
	 * 处理收到的留言
	 * 
	 * @param msg
	 */
	private synchronized void invokeNewNoteMessageReceive(ALMessage msg) {
		startSaveNoteMessage(msg);
	}

	/**
	 * 保存服务器上下发的用户配置文件
	 * 
	 * @param data
	 */
	private void invokeGetUserOptEvent(ALXmppEvent data) {
		if (data.getResponseCode() == ALXmppEvent.RESPONSE_OK) {
			SystemSettings tmp = (SystemSettings) data.getData();
			if (tmp != null) {
				tmp.setSynchronized(true);
				SystemNotificationEnvConfig.getInstance().saveSystemSettings(
						tmp);
				tmp = null;
				SystemNotificationEnvConfig.getInstance()
						.reloadSystemSettings();
			}
		}
	}

	/**
	 * 處理拨号事件
	 * 
	 * @param data
	 */
	private void invokeMakeCallEvent(ALXmppEvent data) {
		// ALVoipCallManager.getDefaultALVoipManager().onCallStateChanged(
		// CallState.CALL_OUTGOING, null);
	}

	/**
	 * 处理新来电事件
	 * 
	 * @param msg
	 */
	private void invokenNewIncommingCallEvent(ALMessage msg) {

		if (msg.isOfflineMessage()) {
			ALLog.d("离线的来电，不管了");
			User u = (User) msg.getData();
			if (u != null) {
				if (u.getCallRecordType() == User.CALL_STATE_MISS) {
					// 来电提醒,保存到數據庫
					ALVoipCallManager.getDefaultALVoipManager()
							.onCallStateChanged(
									CallState.CALL_INCOMMING_NOTICE, msg);
				}
			}
			return;
		}

		User u = (User) msg.getData();
		if (u != null) {
			if (u.getCallRecordType() == User.CALL_STATE_MISS) {
				// 来电提醒,保存到數據庫
				ALVoipCallManager.getDefaultALVoipManager().onCallStateChanged(
						CallState.CALL_INCOMMING_NOTICE, msg);
				return;
			}
		}
		ALLog.d("有来电，开启通话界面");
		Intent i = new Intent(this, CallActivity.class);
		i.putExtra("msg", msg);
		i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		startActivity(i);
		ALVoipCallManager.getDefaultALVoipManager().onCallStateChanged(
				CallState.CALL_INCOMMING, msg);
	}

	/**
	 * 处理被踢下线事件
	 * 
	 * @param data
	 */
	private void invokeConflictEvent(ALXmppEvent data) {
		// 先发消息关闭界面
		ALLocalEnv.getLocalEnv().postFinishAllActivityEvent();
		// 清除本地数据
		ALLocalEnv.getLocalEnv().clearEnv();
		// 跳转到登陆界面
		Intent i = new Intent(this, GetAccountActivity.class);
		i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		startActivity(i);
		// 打出被踢下线提示
		MyToastUtil.getInstance().showToastOnCenter(
				getString(R.string.TxtLoginConflict));
	}

	/**
	 * 处理修改用户资料结果
	 * 
	 * @param data
	 */
	public void handleModifyUserProfileEvent(ALXmppEvent data) {
		if (data.getResponseCode() == ALXmppEvent.RESPONSE_OK) {
			ALLog.d("修改资料成功");
			UserProfileManager.saveMyProfile(ALLocalEnv.getLocalEnv()
					.getMyProfile());
		}
	}

	/**
	 * 处理获取用户资料
	 * 
	 * @param data
	 */
	public void handleGetUserProfileEvent(ALXmppEvent data) {
		if (data.getResponseCode() == 0 && data.getData() != null) {
			User user = (User) data.getData();
			if (ALLocalEnv.getBareJid(user.getJid()).equals(
					ALLocalEnv.getLocalEnv().getMyAccount().getUserName())) {
				// 开始保存自己的资料
				UserProfileManager.saveMyProfile(user);
				ALLocalEnv.getLocalEnv().setMyProfile(user);
				if (sendPresenceRequest) {
					sendPresenceRequest = false;
					// 发送出席
					ALLocalEnv.adapter.xmppSendPresence();
				}
			}

		}
	}

	private boolean isSaveing = false;

	/**
	 * 登陆成功，更新数据库
	 * 
	 * @param data
	 */
	private synchronized void loginedUpdataDataBase(final ALXmppEvent data) {

		new Thread() {
			public void run() {
				// 上傳網絡狀態到服務器
				ALModuleManager
						.getDefaultModuleManager()
						.postEventToModuleManager(
								ALUiXmppRequestCreator
										.creatorALUiXmppEvent(
												ALUiXmppRequestType.XMPP_VOIP_UPLOAD_LOCAL_NETWORK_STAT,
												ALConnectionManager
														.getConnectionTypeString()));

				if (!SystemNotificationEnvConfig.getInstance()
						.getSystemSettings().isSynchronized()) {
					ALLog.d("配置文件与服务器不同步，开始请求");
					ALUiXmppRequestCreator.postALUiXmppGetUserOpt();
				}

				// new Thread() {
				// public void run()
				// {
				if (isSaveing) {
					ALLog.d("正在保存，返回");
					return;
				}

				isSaveing = true;

				String curDataBaseName = ALLocalEnv.getLocalEnv().getDatabase()
						.getDatabaseName();

				ALLocalEnv.getLocalEnv().getDatabase()
						.savePrivateAccount(data.getJid());

				ALLog.d("开始执行保存"
						+ ALLocalEnv.getLocalEnv().getMyAccount().isLogoff());
				ALLog.d("我当前的账号为 "
						+ ALLocalEnv.getLocalEnv().getMyAccount().getUserName());

				ALLog.d("是什么 "
						+ !data.getJid().equals(
								ALLocalEnv.getLocalEnv().getMyAccount()
										.getUserName()));

				if (ALLocalEnv.getLocalEnv().getMyAccount().isLogoff()) {
					// 判断是否要重建数据库

					if (!data.getJid().equals(curDataBaseName)) {
						// 如果登录的不是同一个账号，那么要重建数据库
						ALLog.d("不同的用户，重新打开数据库");
						ALLocalEnv.getLocalEnv().getDatabase()
								.loadDataBase(data.getJid());
					}
				}

				ALLocalEnv.getLocalEnv().getMyAccount().setLogoff(false);
				ALLocalEnv.getLocalEnv().getMyAccount()
						.setUserName(data.getJid());
				ALLocalEnv.getLocalEnv().getMyAccount()
						.setPassWord(data.getPwd());
				ALLocalEnv.getLocalEnv().getMyAccount()
						.setToken(data.getToken());
				ALLocalEnv.getLocalEnv().getDatabase()
						.saveMyAccount(ALLocalEnv.getLocalEnv().getMyAccount());
				// 保存账号密码到数据库

				ALLocalEnv.getLocalEnv().getDatabase().saveSystemSetting(false);
				// };
				// }.start();
				isSaveing = false;

				if (ALLocalEnv.getLocalEnv().isMyProfileEmpty()) {
					ALLog.d("请求我的个人资料");
					ALUiXmppRequestCreator
							.postALUIXmppGetUserProfileEvent(null);
					sendPresenceRequest = true;
				} else {
					ALLog.d("个人资料 "
							+ ALLocalEnv.getLocalEnv().getMyProfile().getJid()
							+ " 昵称 "
							+ ALLocalEnv.getLocalEnv().getMyProfile().getNick());
					// 发送出席
					ALLocalEnv.adapter.xmppSendPresence();
				}

				// if (ALLocalEnv.getLocalEnv().getDatabase().getBlackListSize()
				// == 0)
				{
					ALLog.d("本地黑名单列表为空，开始请求黑名单列表");
					ALUiXmppRequestCreator.postALUiXmppGetUserBlackList();
				}
			};
		}.start();

	}

	/**
	 * 保存黑名单
	 * 
	 * @param data
	 */
	private void invokeSaveBlackListAction(ALXmppEvent data) {
		ALLog.d(" 獲取黑名單返回  " + data.getResponseCode());
		if (data.getResponseCode() == ALXmppEvent.RESPONSE_OK) {
			@SuppressWarnings("unchecked")
			ArrayList<User> users = (ArrayList<User>) data.getData();
			if (users != null && users.size() > 0) {
				startSaveBlackListUsers(users);
			}
		}
	}

	/******************************************* 数据库保存 ******************************************/

	/****************************************** 保存黑名单 *************************************************/
	private ALAsyncTaskCallback saveBlackListCallback = new ALAsyncTaskCallback() {

		@Override
		public Object onTaskStart(Object obj) {
			// TODO Auto-generated method stub
			@SuppressWarnings("unchecked")
			ArrayList<User> users = (ArrayList<User>) obj;
			ALLocalEnv.getLocalEnv().getDatabase().deletBlackList();
			for (User u : users) {
				ALLog.d("开始保存用户到黑名单  " + u.getNick());
				ALLocalEnv.getLocalEnv().getDatabase().insertUserToBlackList(u);
			}
			ALLog.d("保存黑名单完成");
			users.clear();
			users = null;
			return null;
		}

		@Override
		public Object onTaskFinish(Object obj) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public Object onTaskCancel() {
			// TODO Auto-generated method stub
			return null;
		}
	};

	/**
	 * 开始保存系统消息
	 * 
	 * @param msg
	 */
	private void startSaveBlackListUsers(ArrayList<User> users) {
		ALAsycTask task = new ALAsycTask(saveBlackListCallback);
		task.execute(users);
	}

	/****************************************** 保存系统消息 *************************************************/

	/**
	 * 开始保存系统消息
	 * 
	 * @param msg
	 */
	private void startSaveSystemMessage(ALMessage msg) {
		SystemMessageManager.getSystemMessageManager().saveSystemMessage(msg);
	}

	/****************************************** 处理收到的留言消息 *************************************************/
	private void startSaveNoteMessage(ALMessage msg) {
		NoteMessageManager.getNoteMessageManager().saveNoteMessage(msg);
	}

	/****************************************** 处理收到的通话中聊天消息 *************************************************/
	private ALAsyncTaskCallback saveCallImageMessageCallback = new ALAsyncTaskCallback() {

		@Override
		public Object onTaskStart(Object obj) {
			// TODO Auto-generated method stub
			ALMessage msg = (ALMessage) obj;
			ALLog.d("开始保存系统消息 " + msg.getBody());
			String bob = msg.getBob();
			if (TextUtils.isEmpty(bob))
				return null;
			Bitmap bm = null;
			try {
				bm = BitmapUtil.unCompressImage(bob);
			} catch (OutOfMemoryError e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}
			if (bm != null) {
				String filePath = VersionConfig.IMAGE_PATH + "/";
				String fileName = System.currentTimeMillis() + "";
				Uri uri = Uri.fromFile(new File(filePath + fileName));
				BitmapUtil.compressBitmapPng(getApplicationContext(), bm, uri);
				bm.recycle();
				bm = null;
				msg.setFilePath(uri.getPath());
			}

			ALXmppEvent data = new ALXmppEvent(
					ALXmppEventType.XMPP_RECEIVE_NEW_CALL_IMAGE_MESSAGE_EVENT);
			data.setMessage(msg);
			ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
			ALVoipCallManager.getDefaultALVoipManager()
					.onNewCallChatMsgReceived(msg);

			return msg;
		}

		@Override
		public Object onTaskFinish(Object obj) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public Object onTaskCancel() {
			// TODO Auto-generated method stub
			return null;
		}
	};

	/**
	 * 开始保存通话中聊天消息
	 * 
	 * @param msg
	 */
	private void startSaveCallImageMessage(ALMessage msg) {
		if (msg.isOfflineMessage()) {
			ALLog.d("离线的消息，不管了");
			return;
		}
		ALAsycTask saveCallImageMessageTask = new ALAsycTask(
				saveCallImageMessageCallback);
		saveCallImageMessageTask.execute(msg);
	}

	/*********************************************** 分发器数据管理 *****************************************************/
	@Override
	public void onALEvent(DistributorEvent event) {
		// TODO Auto-generated method stub
		ServerInfo info = event.getCheckedServerInfo();
		if (info != null) {
			String splash = info.getSplashUrl();
			if (!TextUtils.isEmpty(splash)) {
				if (ALSplashManager.getInstance().isNeedToUpdateSplashVersion(
						info.getSplashVersion())) {
					ALLog.d("开始下载启动界面 " + info.getSplashVersion());
					ALSplashManager.getInstance().startDownloadSplash(
							ALLocalEnv.getLocalEnv(), splash);
				} else {
					ALLog.d("版本号相同，不需要下载");
				}
			} else {
				ALSplashManager.getInstance().setSplashPath("");
			}
		}
	}

}
